package com.wxg.demo;

import java.util.ArrayList;
import java.util.List;

import com.wxg.entity.EleIdAndBounds;
import com.wxg.entity.MyPage;
import com.wxg.entity.MyPages;
import com.wxg.utils.My;

/**
 * @see com.wxg.demo.Emr102
 * -	* Emr102 中使用的是`bounds.y + height`来定位高度的
 * 
 * 
 * 
 * @author Wxg
 *
 */
public class Emr103 {
	public static void main(String[] args) {
		code101();
	}
	
	public static void code101(){
		String dirpath = "F:\\wxg\\for_print\\myjfserver\\src\\main\\webapp\\uehtml";
		// 附加id属性,并存储html到本地磁盘
		Emr102.storeHtmlWithGenId( dirpath + "\\html_103.html" );
		
		String url = My.fileUrl( Emr102.genFilepath );
		List<EleIdAndBounds> list = Emr103.whosOverPage(url);
		
		if(null != list){
			for(EleIdAndBounds ib : list){
				System.out.println( ib );
			}
		}
		
		// insertHeaderAndFooter( outerHtmlList );
		Emr102.insertHeaderAndFooter();
	}
	
	/**
	 * 不使用`bounds.y+height`, 直接使用`height`
	 * 
	 * @param url
	 * @return
	 */
	public static List<EleIdAndBounds> whosOverPage(String url){
		List<EleIdAndBounds> list = new ArrayList<EleIdAndBounds>();
		List<EleIdAndBounds> ibList = Emr102.getBlockElement(url);
		int len = ibList.size();
		
		int height = 0;
		
		Emr102.pages = new MyPages();
		MyPage page = Emr102.pages.newPage();
		for(int i=0; i<len; i++){
			EleIdAndBounds ib = ibList.get(i);
			height += ib.bounds.height;
			if( height > Emr102.MAIN_HEIGHT ){
				// if( ib.bounds.height <= MIN_H ){  } // 不添加到list中!
				// list.add( ibList.get(i-1) ); // 上一个元素
				list.add( ib ); // 当前元素
				height = ib.bounds.height; // 重新开始计算
				page = Emr102.pages.newPage();
			}
			page.add(ib.id);
		}
System.out.println( height );
		return list;
	}
}
